﻿
using BlondeHeaven.DB.Model;
using BlondeHeaven.DTO;
using BlondeHeaven.DTO.Interface;
using BlondeHeaven.UI.Models;
using BlondeHeaven.UI.Models.Shop;
using Microsoft.AspNetCore.Mvc;

namespace BlondeHeaven.UI.Controllers
{

    public class HomeController : Controller
    {
        private readonly IDTUserService _db;

        public HomeController(IDTUserService db)
        {
            _db = db;
        }
        [HttpGet]
        public IActionResult Index()
        {
            return View();
        }
       

        /// <summary>
        /// 这里是注册
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Register()
        {
            return View();
        }
        [HttpPost]
        public IActionResult Register(RegisterUserViewModel userViewModel1)
        {
            User user = new User()
            {
                PassWrod = userViewModel1.PassWrod,
                Name = userViewModel1.Name,
                Address = userViewModel1.Address,
                Age = userViewModel1.Age,
                Sex = userViewModel1.Sex,
                Phone = userViewModel1.Phone,
                Photo = userViewModel1.Photo
            };
            _db.Add(user, true);
            return View();
        }
        /// <summary>
        /// 这里是登入
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Login()
        {
            return View();
        }
        [HttpPost]
        public IActionResult Login(LoginUserViewModel userViewModel)
        {
            if (ModelState.IsValid)
            {
                User user = new User()
                {
                    Phone = userViewModel.Phone,
                    PassWrod = userViewModel.PassWord
                };
                bool user1 = _db.Login(user.Phone, user.PassWrod);
                if (user1)
                {
                    return RedirectToAction("index");
                }
                else
                {
                    ModelState.AddModelError("", "账号密码错误");
                }
            }
            return View();
        }







    }
}
